/*************************************************************************
	> File Name: Iterator.h
	> Author: Joker
	> Mail: mahongtao@foxmail.com 
	> Created Time: 2020-09-22 18:48:19
 ************************************************************************/

#ifndef __Iterator_H__
#define __Iterator_H__

typedef int DATA;

class Iterator;

class Aggregate{
public:
    virtual ~Aggregate(){}

    virtual Iterator * CreateIterator(Aggregate * pAggregate) = 0;
    virtual int GetSize() = 0;
    virtual DATA GetItem(int idx) = 0;
};

class Iterator
{
public:
    virtual ~Iterator(){}

    virtual void First() = 0;
    virtual void Next() = 0;
    virtual bool IsDone() = 0;
    virtual DATA CurrentItem() = 0;
};

class ConcreateAggregate
:public Aggregate
{
public:
    ConcreateAggregate(int Size);
    virtual ~ConcreateAggregate();

    virtual Iterator * CreateIterator(Aggregate * pAggregate);
    virtual int GetSize();
    virtual DATA GetItem(int idx);

public:
    int _Size;
    DATA * _pData;
};

class ConcreateIterator
:public Iterator
{
public:
    ConcreateIterator(Aggregate * pAggregate);
    virtual ~ConcreateIterator();

    virtual void First();
    virtual void Next();
    virtual bool IsDone();
    virtual DATA CurrentItem();

private:
    Aggregate * _pConcreateAggregate;
    int _idx;
};

#endif
